package org.example.laboratorymanagement.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.laboratorymanagement.mapper.PlanMapper;
import org.example.laboratorymanagement.pojo.PageBean;
import org.example.laboratorymanagement.pojo.Plan;
import org.example.laboratorymanagement.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlanServiceImpl implements PlanService {

    @Autowired
    private PlanMapper planMapper;

    @Override
    public PageBean pagePlans(Integer page, Integer pageSize, String username, String experiment, String local, String date, String time) {
        // 设置分页
        PageHelper.startPage(page, pageSize);

        List<Plan> planList = planMapper.listPlans(username, experiment, local, date, time);
        Page<Plan> p = (Page<Plan>) planList;

        // 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());

        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        planMapper.delete(ids);
    }

    @Override
    public void update(Plan plan) {
        planMapper.update(plan);
    }

    @Override
    public void add(Plan plan) {
        planMapper.add(plan);
    }
}
